Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(refactor): prefer interfaces over concrete classes #457

Merged
merged 3 commits into from
Jan 7, 2022

Conversation

lance
Copy link
Member

@lance lance commented Jan 4, 2022

This change modifies the protocol binding interfaces such as Binding, Serializer and the cloneWith() methods to use the CloudEventV1 interface instead of the implementation class CloudEvent. This should make extending the interfaces simpler as using interfaces decouples Specification Extensions for relying on the concrete CloudEvent class. This work has grown out of efforts around the implementation of a second transport interface, Kafka.

See: #455

In addition, this PR includes:

  • The addition of a generic type to the Message interface, defaulting to string
  • Some minor clean up involving what is exported from the message/http modules. Now, instead of exporting the entire implementation, only the HTTP binding implementation is exported
  • A static CloudEvent.cloneWith() method has been added which the instance methods now use

I'm pretty sure all of this is fully backwards compatible as there were no changes required for the tests.

I will hold on #455 until this has landed, so that I can pull in these changes and keep 455 small-ish.

Signed-off-by: Lance Ball lball@redhat.com

This change modifies the protocol binding interfaces such as `Binding`,
`Serializer` and the like to use the `CloudEventV1` interface instead of the
implementation class `CloudEvent`. This should make extending the interfaces
simpler as this work has grown out of efforts around the implementation of
a second transport interface, Kafka.

See: cloudevents#455

This commit also includes the addition of a generic type to the `Message`
interface, defaulting to `string`.

There is also some minor clean up involving what is exported from the
`message/http` modules. Now, instead of exporting the entire implementation,
only the `HTTP` binding implementation is exported, and it is then reexported
by `message`.

Also, a static `CloudEvent.cloneWith()` method has been added which the
instance methods now use.

Signed-off-by: Lance Ball <lball@redhat.com>
@lance lance added the chore/refactor Refactoring and other non-functional changes to module code label Jan 4, 2022
@lance lance requested a review from a team January 4, 2022 19:04
lance added a commit to lance/sdk-javascript that referenced this pull request Jan 4, 2022
Also, incorporates all of the changes from cloudevents#457

Signed-off-by: Lance Ball <lball@redhat.com>
Signed-off-by: Lance Ball <lball@redhat.com>
@@ -147,7 +147,7 @@ See: https://github.com/cloudevents/spec/blob/v1.0/spec.md#type-system`);
toJSON(): Record<string, unknown> {
const event = { ...this };
event.time = new Date(this.time as string).toISOString();
event.data = !isBinary(this.data) ? this.data : undefined;
event.data = this.#_data;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: It's not clear why we originally were unsetting the data property in this function if it was in binary form. But I don't think we should be doing that. Making this change had no effect on the tests. Happy to discuss what the reason is for this code as it was if anyone recalls.

Signed-off-by: Lance Ball <lball@redhat.com>
@lance lance changed the title chore(refactor): protocol bindings use interfaces chore(refactor): prefer interfaces over concrete classes Jan 5, 2022
@lance lance merged commit 2ac731e into cloudevents:main Jan 7, 2022
@lance lance deleted the lance/prefer-interfaces branch January 7, 2022 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore/refactor Refactoring and other non-functional changes to module code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants